package com.gxa.modules.service.impl;

import com.gxa.common.vo.JsonResult;
import com.gxa.common.vo.PageRecv;
import com.gxa.modules.mapper.CollectionMapper;
import com.gxa.modules.pojo.Collection;
import com.gxa.modules.service.CollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CollectionServiceImpl implements CollectionService{
    @Autowired(required = false)
    private CollectionMapper collectionMapper;


    @Override
    public JsonResult queryCollection(Integer page, Integer limit) {
        JsonResult jsonResult = new JsonResult();
        Integer param1 = (page - 1)*limit;
        Integer param2 = limit;
        List<Collection> collectionMap = collectionMapper.queryCollectionMap(param1,param2);
        int result = collectionMapper.countCollection();
        jsonResult.setCount(result);
        jsonResult.setData(collectionMap);
        jsonResult.setCode(200);
        jsonResult.setMsg("查询成功");
        return jsonResult;
    }

    @Override
    public JsonResult queryCollList(PageRecv<Collection>pageRecv) {
        //对查询页面参数计算
        Integer currentPage=pageRecv.getCurrentPage();
        Integer pageSize=pageRecv.getPageSize();
        Integer limit1=(currentPage-1)*pageSize;
        pageRecv.setCurrentPage(limit1);
        Collection collection=pageRecv.getData();
        //调用mapper方法，返回查询结果list
        List<Collection> list=collectionMapper.searchCollectionListMapper(pageRecv);
        Integer count=collectionMapper.searchCollectionListCountMapper(pageRecv);
        //将list和count条数塞入r,响应成功返回
        JsonResult r=new JsonResult();
        r.setCode(200);
        r.setCount(count);
        r.setMsg("查询成功");
        r.setData(list);

        return r;
    }

    @Override
    public JsonResult queryCollectionList(PageRecv<Collection> pageRecv) {
        JsonResult jsonResult = new JsonResult();
        List<Collection> collectionMap = collectionMapper.queryCollectionList(pageRecv);
        jsonResult.setData(collectionMap);
        jsonResult.setCode(200);
        jsonResult.setMsg("查询成功");
        return jsonResult;
    }
}
